<?php include(TEMPLATE_DIR . 'header.tpl'); ?>
	<?php include(TEMPLATE_DIR . 'nav.tpl'); ?>
	<script type="text/javascript" src="report/scripts/js/pstat.js"></script>
	<div class="main">
		<div class="push_stat_title">
			<h2>Push 发送结果查询</h2>
			<div class="line"></div>
		</div>
		<form id="search_column_form" name="search_column_form" action="" >
		<input type="hidden" name="do" value="<?php echo $this->getVar('action'); ?>" />
		<div class="serach_column_box">
			<span class="title">选择列名:</span>
				<select id="field_name" name="field_name">
					<?php $fieldData = array('token' => '设备标识(token)', 'mid' => '应用自定义ID(mid)'); ?>
					<?php var_dump($query); ?>
					<?php foreach ($fieldData as $value => $label): ?>
						<option value="<?php echo $value; ?>" <?php echo ($value === (string)$query['field_name'] ? 'selected' : ''); ?>><?php echo $label; ?></option>
					<?php endforeach; ?>
				</select>
				<input type="text" id="field_value" name="field_value" value="<?php echo $query['field_value']; ?>" class="input-tips" />
				<span id="query_date_box">
					<span class="title">查询日期:</span>
					<label>从<input type="text" id="query_date_start" name="query_date_start" value="<?php echo isset($query['query_date_start']) ? $query['query_date_start'] : ''; ?>" readonly="readonly" /></label>
					<label>到
					<input type="text" id="query_date_end" name="query_date_end" value="<?php echo isset($query['query_date_end']) ? $query['query_date_end'] : ''; ?>" readonly="readonly" /></label>
				</span>
			&nbsp;
			<input type="button" id="btn_submit"  name="btn_submit" value="查询" />
			</form>
			<?php if(isset($output['data']['total']) && !empty($output['data']['total'])): ?>
				<?php $total = $output['data']['total']; ?>
				<div class="total-box">
					<span class="title">统计信息:</span>
						<span class="stat-text">
							成功数量:<span class="stat-value"><?php echo $this->format($total['count_success']); ?></span>
							平均花费时间(成功):<span class="stat-value">
												<?php if (!is_null($total['avg_spend_time_success'])): ?>
													<span class="second" title="<?php echo $this->format($total['avg_spend_time_success'], 'STD_FLOAT_TIME_FULL'); ?>">
														<?php echo $this->format($total['avg_spend_time_success'], 'STD_FLOAT_TIME'); ?>
													</span>
												<?php else: ?>
													<?php echo $this->format(null); ?>
												<?php endif; ?>
											</span>
							失败数量:<span class="stat-value"><?php echo $this->format($total['count_fail']); ?></span>
							平均花费时间(失败):<span class="stat-value">
												<?php if (!is_null($total['avg_spend_time_fail'])): ?>
													<span class="second" title="<?php echo $this->format($total['avg_spend_time_fail'], 'STD_FLOAT_TIME_FULL'); ?>">
														<?php echo $this->format($total['avg_spend_time_fail'], 'STD_FLOAT_TIME'); ?>
													</span>
												<?php else: ?>
													<?php echo $this->format(null); ?>
												<?php endif; ?>
											</span>
							未处理数量:<span class="stat-value"><?php echo $this->format($total['count_pending']); ?></span>
							
						</span>
					</span>
				</div>
			<?php endif; ?>
		</div>
	
		<div class="push_stat_table_box">
			<table class="push_stat_table" border="0" width="100%">
				<tr align="center" valign="middle">
					<th>ID</th>
					<th>产品名称</th>
					<th>Token</th>
					<th>应用自定义ID</th>
					<th>标题</th>
					<th>接收时间</th>
					<th>发送时间</th>
					<th>花费时间</th>
					<th>发送结果</th>
					<th>操作</th>
				</tr>
				<?php if (isset($output['data']['list']) && !empty($output['data']['list'])): ?>
					<?php foreach($output['data']['list'] as $key => $row): ?>
						<tr>
							<td><?php echo $this->format($row['id']); ?></td>
							<td><?php echo isset($output['prods'][$row['prod']]) ? $output['prods'][$row['prod']]['name'] : '--'; ?></td>
							<td><?php echo $this->format($row['token']); ?></td>
							<td><?php echo $this->format($row['mid']); ?></td>
							<td><?php echo $this->format($row['title']); ?></td>
							<td><?php echo $this->format($row['tmr'], 'STD_DATETIME'); ?></td>
							<td><?php echo $this->format(($this->getSendResult($row['tms']) !== 0 ? abs($row['tms']) : null), 'STD_DATETIME'); ?></td>
							<td>
								<?php if ($this->getSendResult($row['tms']) !== 0) : ?>
									<?php $spendTime = (abs($row['tms']) - $row['tmr']); ?>
									<span class="second" title="<?php echo $this->format($spendTime, 'STD_FLOAT_TIME_FULL'); ?>">
										<?php echo $this->format($spendTime, 'STD_FLOAT_TIME'); ?>
									</span>
								<?php else: ?>
									<?php echo $this->format(null); ?>
								<?php endif; ?>
							</td>
							<td><?php echo $this->getSendResult($row['tms'], true); ?></td>
							<td><a href="#" onclick="pstat.show_detail('<?php echo $row['id']; ?>');">详细</a></td>
						</tr>
					<?php endforeach; ?>
					<tr>
						<td colspan="10">
							<?php include(TEMPLATE_DIR . '/pager.tpl'); ?>
						</td>
					</tr>
				<?php else: ?>
					<tr>
						<td colspan="10">
						</td>
					</tr>
				<?php endif; ?>
			</table>
		</div>
	</div>
<script type="text/javascript">
	$(function(){
		// 加载表单初始设置
		pstat.loadForm('search_column_form');
	});
</script>
<?php include(TEMPLATE_DIR . '/footer.tpl'); ?>
